import { onMounted, nextTick, ref, reactive, watch } from "vue";
import axios from "axios";
import { ElMessage } from "element-plus";

const url = import.meta.env.VITE_backurl;
const urlYbd = import.meta.env.VITE_backurl_java;

// export const currentAlarm = ref(0),
//   currentPub = ref(0), 
//   currentGrade = ref(0),
//   currentDate = ref(''),
//   currentHour = ref('10');

export const alarmTypes = [
    {
      value: 0,
      label: "海浪",
    },
    {
      value: 1,
      label: "天文潮",
    },
    {
      value: 2,
      label: "风暴潮",
    },
  ],
  alarmSubjects = [
    {
      value: 0,
      label: "台风",
    },
    {
      value: 1,
      label: "冷空气",
    },
  ],
  pubTypes = [
    {
      value: 0,
      label: "消息",
    },
    {
      value: 1,
      label: "警报",
    },
    {
      value: 2,
      label: "警报解除通报",
    },
  ],
  gradeTypes = [
    {
      value: 0,
      label: "I级（红色）",
    },
    {
      value: 1,
      label: "II级（橙色）",
    },
    {
      value: 2,
      label: "III级（黄色）",
    },
    {
      value: 3,
      label: "IV级（蓝色）",
    },
  ],
  regions = [
    {
      value: "wz",
      label: "温州",
      station: ["沙港头", "龙湾", "温州", "洞头", "瑞安", "鳌江", "石砰"],
      twcItem: [
        {
          code: "乐清市东岸北段",
          station: "沙港头",
          lan: "400",
          huang: "425",
          cheng: "450",
          hong: "475",
        },
        {
          code: "乐清市东岸南段",
          station: "沙港头",
          lan: "395",
          huang: "420",
          cheng: "445",
          hong: "470",
        },
        {
          code: "乐清市瓯江口段",
          station: "龙湾",
          lan: "390",
          huang: "415",
          cheng: "435",
          hong: "460",
        },
        {
          code: "灵昆岛岸段",
          station: "龙湾",
          lan: "385",
          huang: "410",
          cheng: "430",
          hong: "455",
        },
        {
          code: "龙湾区岸段",
          station: "龙湾",
          lan: "395",
          huang: "415",
          cheng: "440",
          hong: "460",
        },
        {
          code: `鹿城区段、七都岛段、永嘉县段`,
          station: "温州",
          lan: "400",
          huang: "430",
          cheng: "460",
          hong: "490",
        },
        {
          code: "洞头区大门镇段、洞头区洞头岛段",
          station: "洞头",
          lan: "350",
          huang: "370",
          cheng: "390",
          hong: "410",
        },
        {
          code: `瑞安市岸段`,
          station: "瑞安",
          lan: "385",
          huang: "410",
          cheng: "435",
          hong: "465",
        },
        {
          code: `平阳县岸段`,
          station: "鳌江",
          lan: "385",
          huang: "405",
          cheng: "430",
          hong: "450",
        },
        {
          code: `龙港市岸段`,
          station: "鳌江",
          lan: "385",
          huang: "410",
          cheng: "435",
          hong: "460",
        },
        {
          code: `苍南县东岸北段、苍南县东岸南段`,
          station: "石砰",
          lan: "355",
          huang: "380",
          cheng: "400",
          hong: "425",
        },
      ],
    },
    {
      value: "cn",
      label: "苍南",
      station: ["石砰"],
      twcItem: [
        {
          code: `苍南县东岸北段、苍南县东岸南段`,
          station: "石砰",
          date: "",
          time: "",
          tide: "",
          lan: "355",
          huang: "380",
          cheng: "400",
          hong: "425",
          level: "",
        },
      ],
    },
    {
      value: "py",
      label: "平阳",
      station: ["鳌江"],
      twcItem: [
        {
          code: "平阳县岸段",
          station: "鳌江",
          date: "",
          time: "",
          tide: "",
          lan: "385",
          huang: "405",
          cheng: "430",
          hong: "450",
          level: "",
        },
      ],
    },
    {
      value: "ra",
      label: "瑞安",
      station: ["瑞安"],
      twcItem: [
        {
          code: "瑞安市岸段",
          station: "瑞安",
          lan: "385",
          huang: "410",
          cheng: "435",
          hong: "465",
        },
      ],
    },
    {
      value: "sa",
      label: "三澳",
      station: ["石砰"],
      twcItem: [
        {
          code: "三澳岸段",
          station: "石砰",
          date: "",
          time: "",
          tide: "",
          lan: "355",
          huang: "380",
          cheng: "400",
          hong: "425",
          level: "",
        },
      ],
    },
    {
      value: "qt",
      label: "浅滩",
      station: ["龙湾"],
      twcItem: [
        {
          code: "浅滩工程岸段",
          station: "龙湾",
          date: "",
          time: "",
          tide: "",
          lan: "385",
          huang: "410",
          cheng: "430",
          hong: "455",
          level: "",
        },
      ],
    },
    {
      value: "hz",
      label: "海灾智治",
      station: ["沙港头", "龙湾", "温州", "洞头", "瑞安", "鳌江", "石砰"],
      twcItem: [
        {
          code: "乐清市东岸北段",
          station: "沙港头",
          lan: "400",
          huang: "425",
          cheng: "450",
          hong: "475",
        },
        {
          code: "乐清市东岸南段",
          station: "沙港头",
          lan: "395",
          huang: "420",
          cheng: "445",
          hong: "470",
        },
        {
          code: "乐清市瓯江口段",
          station: "龙湾",
          lan: "390",
          huang: "415",
          cheng: "435",
          hong: "460",
        },
        {
          code: "灵昆岛岸段",
          station: "龙湾",
          lan: "385",
          huang: "410",
          cheng: "430",
          hong: "455",
        },
        {
          code: "龙湾区岸段",
          station: "龙湾",
          lan: "395",
          huang: "415",
          cheng: "440",
          hong: "460",
        },
        {
          code: `鹿城区段、七都岛段、永嘉县段`,
          station: "温州",
          lan: "400",
          huang: "430",
          cheng: "460",
          hong: "490",
        },
        {
          code: `洞头区大门镇段、洞头区洞头岛段`,
          station: "洞头",
          lan: "350",
          huang: "370",
          cheng: "390",
          hong: "410",
        },
        {
          code: `瑞安市岸段`,
          station: "瑞安",
          lan: "385",
          huang: "410",
          cheng: "435",
          hong: "465",
        },
        {
          code: `平阳县岸段`,
          station: "鳌江",
          lan: "385",
          huang: "405",
          cheng: "430",
          hong: "450",
        },
        {
          code: `龙港市岸段`,
          station: "鳌江",
          lan: "385",
          huang: "410",
          cheng: "435",
          hong: "460",
        },
        {
          code: `苍南县东岸北段、苍南县东岸南段`,
          station: "石砰",
          lan: "355",
          huang: "380",
          cheng: "400",
          hong: "425",
        },
      ],
    },
    {
      value: "lw",
      label: "龙湾",
      station: ["龙湾"],
      twcItem: [
        {
          code: "瑞安市岸段",
          station: "瑞安",
          lan: "385",
          huang: "410",
          cheng: "435",
          hong: "465",
        },
      ],
    },
    {
      value: "lg",
      label: "龙港",
      station: ["龙港"],
      twcItem: [
        {
          code: "瑞安市岸段",
          station: "瑞安",
          lan: "385",
          huang: "410",
          cheng: "435",
          hong: "465",
        },
      ],
    },
    {
      value: "lq",
      label: "乐清",
      station: ["乐清"],
      twcItem: [
        {
          code: "瑞安市岸段",
          station: "瑞安",
          lan: "385",
          huang: "410",
          cheng: "435",
          hong: "465",
        },
      ],
    },
  ],
  hours = [
    {
      value: 0,
      label: "00",
    },
    {
      value: 1,
      label: "01",
    },
    {
      value: 2,
      label: "02",
    },
    {
      value: 3,
      label: "03",
    },
    {
      value: 4,
      label: "04",
    },
    {
      value: 5,
      label: "05",
    },
    {
      value: 6,
      label: "06",
    },
    {
      value: 7,
      label: "07",
    },
    {
      value: 8,
      label: "08",
    },
    {
      value: 9,
      label: "09",
    },
    {
      value: 10,
      label: "10",
    },
    {
      value: 11,
      label: "11",
    },
    {
      value: 12,
      label: "12",
    },
    {
      value: 13,
      label: "13",
    },
    {
      value: 14,
      label: "14",
    },
    {
      value: 15,
      label: "15",
    },
    {
      value: 16,
      label: "16",
    },
    {
      value: 17,
      label: "17",
    },
    {
      value: 18,
      label: "18",
    },
    {
      value: 19,
      label: "19",
    },
    {
      value: 20,
      label: "20",
    },
    {
      value: 21,
      label: "21",
    },
    {
      value: 22,
      label: "22",
    },
    {
      value: 23,
      label: "23",
    },
  ],
  columns = [
    {
      title: "预警岸段",
      dataIndex: "code",
      width: 150,
    },
    {
      title: "站点",
      dataIndex: "station",
      width: 150,
    },
    {
      title: "日期",
      dataIndex: "date",
      width: 150,
    },
    {
      title: "时间",
      dataIndex: "time",
      width: 150,
    },
    {
      title: "潮位",
      dataIndex: "tide",
      width: 150,
    },
    {
      title: "蓝色",
      dataIndex: "lan",
      width: 150,
    },
    {
      title: "黄色",
      dataIndex: "huang",
      width: 150,
    },
    {
      title: "橙色",
      dataIndex: "cheng",
      width: 150,
    },
    {
      title: "红色",
      dataIndex: "hong",
      width: 150,
    },
    {
      title: "警报等级",
      dataIndex: "level",
      width: 150,
    },
    {
      title: "操作",
      dataIndex: "operation",
      width: 150,
    },
  ];
export const subAlarm = (data) => {
  return axios({
    method: "post",
    url: url + "/wz/subAlarm",
    data: data,
  });
};

export const delAlarm = (data) => {
  return axios({
    method: "post",
    url: url + "/wz/delAlarm",
    data: data,
  });
};

export const getAlarm = (data) => {
  return axios({
    method: "get",
    url: url + "/wz/getAlarm",
    params: data,
  });
};

export const getAlarmLast = (data) => {
  return axios({
    method: "get",
    url: url + "/wz/getAlarmLast",
    params: data,
  });
};

export const getAlarmLastByBh = (data) => {
  return axios({
    method: "get",
    url: url + "/wz/getAlarmLastByBh",
    params: data,
  });
};

// deleteAlarm
export const deleteAlarm = (data) => {
  return axios({
    method: "post",
    url: url + "/wz/deleteAlarm",
    params: data,
  });
};

export const lookAlarm = (data) => {
  return axios({
    method: "get",
    url: url + "/jb/" + data,
    responseType: "blob",
    params: {
      time: new Date().getTime(),
    },
  });
};

export const getTwc = (data) => {
  return axios({
    method: "get",
    url: url + "/wz/getTwc",
    params: data,
  });
};

export const createJb = (data) => {
  return axios({
    method: "post",
    url: urlYbd + "/jb",
    data: data.data,
  });
};

export const getAlarmByConfig = (data) => {
  return axios({
    method: "get",
    url: url + "/wz/getAlarmByConfig",
    params: data,
  });
};

export const getTf = (data) => {
  return axios({
    method: "get",
    url: url + "/wz/getTf",
  });
};

export const getAlarmByDay = (data) => {
  return axios({
    method: "get",
    url: url + "/wz/getAlarmByDay",
    params: data,
  });
};

export const tipsContent = {
  wave: {
    lan: [
      {
        id: 1,
        value: "组织海上作业船只回港避浪",
      },
      {
        id: 2,
        value: "提前做好涉海设施安全管理工作",
      },
      {
        id: 3,
        value:
          "组织洞头、南麂、北麂及北龙等海岛旅游人员的撤岛；关闭旅游航线；关闭沙滩、海水浴场及岸边滨海旅游各项设施",
      },
      {
        id: 4,
        value: "严禁无关人员靠近岸边，避免发生意外",
      },
      {
        id: 5,
        value: "大型在建涉海工程提前做好应急管理工作",
      },
      {
        id: 6,
        value: "加固渔排、网箱等养殖生产设施",
      },
    ],
    huang: [
      {
        id: 7,
        value: "做好沿海低洼路段公路管理工作",
      },
    ],
    cheng: [
      {
        id: 8,
        value: "加强堤塘、港口码头等沿海工程设施的巡视",
      },
    ],
    hong: [],
  },
  fbc: {
    lan: [
      {
        id: 1,
        value: "提前做好涉海设施安全管理工作",
      },
      {
        id: 2,
        value: "提前疏散沿岸相关人员",
      },
      {
        id: 3,
        value: "加强沿海养殖堤塘、沿江上游土石堤等非标准堤的巡查",
      },
      {
        id: 4,
        value: "关闭海水浴场、滨海旅游等项目，及时疏散海边观潮人员",
      },
    ],
    huang: [
      {
        id: 5,
        value:
          "加强对河口、沿岸海堤、水闸及其它海岸工程的巡查，及时做好水闸围堰、堤身两侧及堤头的加固保护工作和施工通道口、海塘开口等薄弱环节的封堵工作",
      },
    ],
    cheng: [
      {
        id: 6,
        value:
          "及时加强港口、码头等重点部位的防范及应急物资储备，转移低洼地带货物",
      },
      {
        id: 7,
        value: "及时组织沿海低洼地带居民疏散到安全地区",
      },
      {
        id: 8,
        value: "鹿城区江心屿堤塘高程较低，易发生漫堤风险，及时组织人员撤离",
      },
    ],
    hong: [
      {
        id: 9,
        value: "做好灵霓大堤的应急管理",
      },
      {
        id: 10,
        value: "沿海沿江地区要注意防范海水漫堤及倒灌引起的淹没、内涝风险",
      },
    ],
  },
};


export const getAlarmType=(data)=>{
  return axios({
    method: "get",
    url: url + "/wz/getAlarmType",
    params: data,
  });
}

export const updateAlarmType=(data)=>{
  return axios({
    method: "post",
    url: url + "/wz/updateAlarmType",
    data: data,
  });
}

export const normColor={
  lan:'#00a0e9',
  huang:'#edc300',
  cheng:'#ee7700',
  hong:'#e60012',
  hui:'#ababab',
  bai:'#ffffff'
}

export const savePng=(data)=>{
  return axios({
    method: "post",
    url: url + "/up/savePng",
    data: data,
  });
}

// 判断早上还是晚上还是中午
export const getZw = (hour) => {
  // let hour = new Date().getHours();

//   白天
// 夜间
// 早晨
// 上午
// 中午
// 下午
// 傍晚
// 上半夜
// 半夜
// 下半夜
// 北京时间
// 08:00~20:00
// 20:00~08:00
// 05:00~08:00
// 08:00~11:00
// 11:00~14:00
// 14:00~17:00
// 17:00~20:00
// 20:00~23:00
// 23:00~02:00
// 02:00~05:00
  hour=Number(hour);
  if (hour > 6 && hour < 18) {
    return '早';
  } else {
    return '晚';
  }
};

// 比较两个时间的大小
export const compareTime = (time1, time2) => {
  let t1 = new Date(time1).getTime(),
    t2 = new Date(time2).getTime();
  if (t1 > t2) {
    return 1;
  } else if (t1 < t2) {
    return -1;
  } else {
    return 0;
  }
};